import java.util.*;

// Hello.java
public class Hello {
    public static void main(String[] args) {
        int[] a = { 0, 2, 3 };
        System.out.println(solve(a));
    }

    class SolutionOfSameLeaves {
        ArrayList<Integer> list1 = new ArrayList<Integer>();
        ArrayList<Integer> list2 = new ArrayList<Integer>();

        public boolean leafSimilar(TreeNode root1, TreeNode root2) {
            getLeaves(root1, list1);
            getLeaves(root2, list2);
            return list1.equals(list2);

        }

        // 单个栈实现深度优先搜索
        public void getLeaves1(TreeNode root, ArrayList<Integer> list) {
            Stack<TreeNode> s = new Stack<TreeNode>();
            s.push(root);
            while (!s.isEmpty()) {
                TreeNode temp = s.pop();
                if (temp.left == null && temp.right == null) {
                    list.add(temp.val);
                } else {
                    if (temp.left != null) {
                        s.push(temp.left);
                    }
                    if (temp.right != null) {
                        s.push(temp.right);
                    }
                }
            }
        }

        // 递归实现先序遍历
        public void getLeaves(TreeNode root, ArrayList<Integer> list) {
            if (root == null)
                return;
            if (root.left == null && root.right == null) {
                list.add(root.val);
            } else {
                getLeaves(root.left, list);
                getLeaves(root.right, list);
            }
        }
    }

    public static int solve(int[] a) {
        // write code here
        int n = a.length + 1;
        for (int i = 0; i < n / 2; ++i) {
            if (a[i] + a[n - i - 2] > n - 1) {
                return n - 1 - a[n - i - 2];
            }
            if (a[i] + a[n - i - 2] < n - 1) {
                return n - 1 - a[i];
            }
        }
        return 0;
    }

    public static int rob(int[] nums) {
        int len = nums.length;
        if (len == 1)
            return nums[0];
        return Math.max(myRob(Arrays.copyOfRange(nums, 0, len - 1)), myRob(Arrays.copyOfRange(nums, 1, len)));
    }

    public static int myRob(int[] nums) {
        int pre = 0, cur = 0, temp;
        for (int num : nums) {
            temp = cur;
            cur = Math.max(pre + num, cur);
            pre = temp;
        }
        return cur;
    }

    public static int FirstNotRepeatingChar(String str) {
        HashMap<Character, Integer> count = new HashMap<Character, Integer>();
        char[] ch = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
                't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
                'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
        for (int i = 0; i < ch.length; ++i)
            count.put(ch[i], 0);
        char[] tempstr = str.toCharArray();
        for (int i = 0; i < tempstr.length; ++i) {
            count.replace(tempstr[i], count.get(tempstr[i]), count.get(tempstr[i]) + 1);
        }
        for (int i = 0; i < tempstr.length; ++i) {
            if (count.get(tempstr[i]) == 1)
                return i;
        }
        return -1;
    }

}

class Trie {
    private Trie[] children;
    private boolean isEnd;

    public Trie() {
        children = new Trie[26];
        isEnd = false;
    }

    public void insert(String word) {
        Trie node = this;
        for (int i = 0; i < word.length(); i++) {
            char ch = word.charAt(i);
            int index = ch - 'a';
            if (node.children[index] == null) {
                node.children[index] = new Trie();
            }
            node = node.children[index];
        }
        node.isEnd = true;
    }

    public boolean search(String word) {
        Trie node = searchPrefix(word);
        return node != null && node.isEnd;
    }

    public boolean startsWith(String prefix) {
        return searchPrefix(prefix) != null;
    }

    private Trie searchPrefix(String prefix) {
        Trie node = this;
        for (int i = 0; i < prefix.length(); i++) {
            char ch = prefix.charAt(i);
            int index = ch - 'a';
            if (node.children[index] == null) {
                return null;
            }
            node = node.children[index];
        }
        return node;
    }
}